home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.inap.net!news1!ind-009-237-118
- From: dlmiller@iquest.net (Doug Miller)
- Subject: Re: reversing a string
- X-Nntp-Posting-Host: ind-009-237-118.iquest.net
- Message-ID: <DpM3Kz.6t4@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <4k6cjl$j8f@central.server.swt.edu> <4kb1s7$6eu@ibm32.perftech.com> <829058514snz@genesis.demon.co.uk> <4ke0b9$rk5@grimsel.zurich.ibm.com>
- Date: Tue, 9 Apr 1996 20:31:47 GMT
-
- wgk@zurich.ibm.com (Keith Whittingham) wrote:
- >Ole! (pronounced Spanishly but written 'olleh')
- >
- >Well here's a starter - no second variable but two recursive functions.
- >Hopefully that can be reduced to one if my project can spare the time.
- >(Note to manager: don't worry, just joking).
- >
- >#include <stdio.h>
- >
- >void RecRev2(char *s)
- > {
- > if(s[1])
- > {
- > if(s[2])
- > {
- > RecRev2(&s[1]);
- > }
- > s[0] ^= s[1]; s[1] ^= s[0]; s[0] ^= s[1];
- > }
- > }
- >
- >void RecRev1(char *s)
- > {
- > if(s && *s)
- > {
- > RecRev2(s);
- > RecRev1(&s[1]);
- > }
- > }
- >
- >int main(int argc, char *argv)
- > {
- > char *s = "Hello";
- > RecRev1(s);
- > puts(s);
- > return 0;
- > }
- >
- This breaks if the string begins and ends with the same character.
-